home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0211_Checking Disk in Drive.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  1.4 KB  |  57 lines

  1.  
  2. {With my last project if a disk is not in say one of the Floppy drives
  3. or my CDRom drive it will crash so i used this function that borland
  4. suggest
  5. }
  6.  
  7. function DiskInDrive(Drive: Char): Boolean;
  8. var
  9.   ErrorMode: word;
  10.  
  11. ok it stops the program from crashing but it shows
  12. I/O 32 error message the question is how do i show them another message
  13. telling the user that thay need to pop in a disk.
  14. And pop the Drive Combo box back to the Hard Drive.
  15. <<<<<<<<<<<<<<<<<<
  16.  
  17. I'm using the following snippet in cmbDrive.OnChange event. Be sure NOT
  18. to connect lstDir through DirList property of cmbDrive. It's a bit like a
  19. batch file, but it works for me OK in Delphi 2 :)
  20.  
  21. procedure TfrmMain.cmbDriveChange(Sender: TObject);
  22. var
  23.    OldDrive: char;
  24.  
  25. label
  26.    Retry;
  27.  
  28.    function SetDrive(const NewDrive: char): boolean;
  29.    begin
  30.       try
  31.          lstDir.Drive := NewDrive;
  32.          Result := true;
  33.       except
  34.          Result := false;
  35.       end;
  36.    end;
  37.  
  38. begin
  39.  
  40. Retry:
  41.    OldDrive := lstDir.Drive;
  42.  
  43.    if not SetDrive(cmbDrive.Drive) then begin
  44.       beep;
  45.       if MessageBox(Handle, PChar(UpperCase(cmbDrive.Drive) + ':\ is not accessible.'#13#13'Drive not ready.'),
  46.          'Error', mb_RetryCancel or mb_IconStop or mb_DefButton1) =
  47. IDRETRY then
  48.             goto Retry
  49.       else
  50.          begin
  51.             lstDir.Drive := OldDrive;
  52.             cmbDrive.Drive := lstDir.Drive;
  53.          end;
  54.    end;
  55.  
  56. end;
  57.